#!/bin/bash
# 1)filtering out NaN cols.
# 2)del cols /wo lat/lon, assign h to 0 when it's null when lat/lon are available.
# 3)del cols /wo wlan macs or rsss.

#awk -F'\",\"' '
awk -F, '
BEGIN {
    OFS=","
} 
{
    if (NF == 16){
        ilat=12; ilon=13; ih=14; imac=15; irss=16
    }else if (NF == 14){
        ilat=9; ilon=10; ih=11; imac=12; irss=13
    }else{
        print "Unsupported format!"
        exit 
    }
    #if($imac!="\"\"" && $irss!="\"\"" && $ilat!="\"\"" && $ilon!="\"\""){ 
    if($imac!="" && $irss!="" && $ilat!="" && $ilon!=""){ 
        if($ih==""){
            $ih=0
		}else{
        	print 
		}
    } 
} ' $1 |grep -v 'NaN'
